/*
 Navicat Premium Dump SQL

 Source Server         : 高斯本地
 Source Server Type    : PostgreSQL
 Source Server Version : 90204 (90204)
 Source Host           : localhost:5432
 Source Catalog        : fire_alarm_dev
 Source Schema         : {{ db_model }}

 Target Server Type    : PostgreSQL
 Target Server Version : 90204 (90204)
 File Encoding         : 65001
*/


-- ----------------------------
-- Table structure for {{ table_name }}
-- ----------------------------
DROP TABLE IF EXISTS "{{ db_model }}"."{{ table_name }}";
CREATE TABLE "{{ db_model }}"."{{ table_name }}" (
{% for column in columns %}
  "{{ column.列名 }}" {{ column.DB类型 }}{% if column.数据长度 %} ({{ column.数据长度 }}){% endif %}{% if column.必填 == 'Y' %} NOT NULL{% endif %}{% if column.默认值 %} DEFAULT {{ column.默认值 }}{% endif %}{% if not loop.last %},{% endif %}
{% endfor %}
)
WITH (fillfactor=80)
;
ALTER TABLE "{{ db_model }}"."{{ table_name }}" OWNER TO "gaussdb";

{% if table_comm %}
COMMENT ON TABLE "{{ db_model }}"."{{ table_name }}" IS '{{ table_comm }}';
{% endif %}

{% for column in columns %}
{% if column.注解 %}
COMMENT ON COLUMN "{{ db_model }}"."{{ table_name }}"."{{ column.列名 }}" IS '{{ column.注解 }}';
{% endif %}
{% endfor %}


-- ----------------------------
-- Indexes structure for table {{ table_name }}
-- ----------------------------
{% for column in columns if column.列名 == 'is_del' %}
CREATE INDEX "idx_{{ table_name }}_is_del" ON "{{ db_model }}"."{{ table_name }}" USING btree (
  "is_del" "pg_catalog"."int2_ops" ASC NULLS LAST
);
{% endfor %}

-- ----------------------------
-- Primary Key structure for table {{ table_name }}
-- ----------------------------
{% for column in columns if column.列名 == 'id' %}
ALTER TABLE "{{ db_model }}"."{{ table_name }}" ADD CONSTRAINT "{{ table_name }}_pk" PRIMARY KEY ("{{ column.列名 }}");
{% endfor %}
